<?php

namespace Modules\ShopAdmin\Models;
use Modules\AuthAdmin\Services\QueryService;
class ShopUser extends BaseApiModel
{
	private function gender_list(){
		return [
			'0'=>'未知',
			'1'=>'男',
			'2'=>'女'
		];
	}
	/**
     * @name   状态0和1修改为true或false
     * @param  int  $value
     * @return Boolean 
     */
    public function getGenderAttribute($value)
    {
        return $this->gender_list()[$value];
    }
	/**
     * @name   更新时间为null时返回
     * @param  int  $value
     * @return Boolean 
     */
    public function getUpdatedAtAttribute($value)
    {
        return $value?$value:'';
    }
	/**
	 * @name  用户列表
	 * @param  data  array 搜索数据
	 * @return json 
	 */
    public function list_data($data){
		$model = $this->query();
		$model = (new QueryService())->query_condition($model,$data,'nick_name');
		if(isset($data['gender']) && $data['gender']>=0){
			$model = $model->where('gender',$data['gender']);
		}	
        $list = $model->select('id','nick_name','avatar_url','gender','created_at')
				->orderBy('id','desc') 
				->paginate($data['pagesize'])
				->toArray(); 
		return $this->api_success(['data'=>[
			'list'=>$list['data'],
			'total'=>$list['total']
		]]);		
	}
}
